/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package contest.util;

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 *
 * @author Admin
 */
public class FileUtil {

    public static boolean isExists(String path) {
        if (path == null) {
            return false;
        }
        File file = new File(path);
        if (file != null) {
            return file.exists();
        }
        return false;
    }

    public static String getExtension(String fullPath) {
        int dot = fullPath.lastIndexOf(".");
        return fullPath.substring(dot + 1);
    }

    public static String getContentFile(String path) throws FileNotFoundException, IOException {
        FileInputStream fstream = null;
        DataInputStream in = null;
        BufferedReader br = null;
        fstream = new FileInputStream(path);
        in = new DataInputStream(fstream);
        br = new BufferedReader(new InputStreamReader(in));
        String strLine;
        String result = "";
        while ((strLine = br.readLine()) != null) {
            result += (strLine) +"\r\n";
        }
        in.close();
        return result;
    }
}
